package cc.geguo.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import cc.geguo.entity.Admin;

/**
 * Created by 13687 on 2017/2/19.
 * 用户登陆拦截器
 */
public class UserLoginInterceptor extends AbstractInterceptor{
	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		ActionProxy proxy = actionInvocation.getProxy();
		String method = proxy.getMethod();
		if (!method.equals("login")){
			Admin userInfo  = (Admin) ActionContext.getContext().getSession().get("userInfo");
			if (userInfo!=null){
				actionInvocation.invoke();
			}else {
				return "input";//跳转到登陆
			}
		}else {
			actionInvocation.invoke();
		}
		return null;
	}
}
